import request from '@/utils/request';

export function roleList(): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/role/roleList',
		method: 'get',
	});
}

export function fetchList(query: any): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/role/page',
		method: 'get',
		params: query,
	});
}

export function deptRoleList(): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/role/list',
		method: 'get',
	});
}

export function getObj(id: any): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/role/' + id,
		method: 'get',
	});
}

export function getObjByCode(code: any): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/role/code/' + code,
		method: 'get',
	});
}

export function addObj(obj: any): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/role',
		method: 'post',
		data: obj,
	});
}

export function putObj(obj: any): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/role',
		method: 'put',
		data: obj,
	});
}

export function delObj(id: any): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/role/' + id,
		method: 'delete',
	});
}

export function permissionUpd(roleId: any, menuIds: any): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/role/menu',
		method: 'put',
		data: {
			roleId: roleId,
			menuIds: menuIds,
		},
	});
}

export function fetchRoleTree(roleId: any): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/menu/tree/' + roleId,
		method: 'get',
	});
}

// 获取角色信息模板
export function fetchRoleTemplate(name: any): ApiPromise<ApiResponse> {
	return request({
		url: '/admin/sys-file/local/file/' + name,
		method: 'get',
		responseType: 'blob',
	});
}
